package net.oschina.app.Page;

import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import net.oschina.app.SoloWrap;

/**
 * Created by kola on 2017/3/22.
 * 登陆页面page类抽取
 */

public class PageLogin {
    private SoloWrap solo;
    private EditText nameET, pwdET;
    private Button loginBtn;
    private ImageButton backBtn;

    public PageLogin(SoloWrap solo) {

        this.solo = solo;
    }

    public void initViews() {
        solo.waitForText("还可以使用其他账号登录");
        nameET = (EditText) solo.getView("net.oschina.app:id/et_username");
        pwdET = (EditText) solo.getView("net.oschina.app:id/et_password");
        loginBtn = (Button) solo.getView("net.oschina.app:id/btn_login");
        backBtn = solo.getImageButton(0);
    }

    public void enterName(String name) {

        solo.enterText(nameET,name);
    }

    public void enterPwd(String pwd) {
        solo.enterText(pwdET, pwd);
    }

    public void clearName() {
        solo.clearEditText(nameET);
    }

    public void clearPwd() {
        solo.clearEditText(pwdET);
    }

    public void clickLoginBtn() {
        solo.clickOnView(loginBtn);
    }

    public void clickBackBtn() {
        solo.clickOnView(backBtn);
    }

    public void login(String username, String password) {
        clearName();
        enterName(username);
        clearPwd();
        enterPwd(password);
        clickLoginBtn();

    }

}
